/**
 * newsList
 */
define(function(require) {
	var comm = require('sdk/server');
	require('sdk/common');
	
	var dataTemp = $('#newsListTemp').val();
	var dataRender = function(data, getMore) {
		var render = etpl.compile(dataTemp);
		var html = render(data);
		if (getMore) {
			$('#newsList').append(html).scrollLoad(function(){
				getData(true)
			});
		} else {
			$('#newsList').html(html).scrollLoad(function(){
				getData(true)
			});
		};
        appcan.loading.hide();
	};
	var getData = function(getMore) {
		appcan.loading.show();
	    appcan.toload({
            url: appcfg.host.control+'/core/service/app/wcm/cms/notice/control.jsp',
            size: 5,
            reload: !getMore,
            data: {
                method:'getNewsList',
                sid:appcfg.project.sid,
            },
            success: function(res) {
            	appcan.window.resetBounceView(getMore ? 1 : 0);
                if (res.status === 'Y') {
                    dataRender(res, getMore);
                } else {
                	appcan.loading.hide();
                    $('#newsList').empty();
                    $.box.msg(res.message, {
                        color: 'danger',
                        delay: 2000
                    });
                }
            }
        });
	}
	//打开详细页
	$('#newsList').on('click', '.item', function() {
		var aid = $(this).data('id');
		if (aid) {
			appcan.openView({
				param: {
					title: '最新动态',
					id: aid,
                    url:'/core/service/app/wcm/cms/notice/control.jsp',
                    method:'getNewsDetail'
				}
			}, 'news', 'detail');
		}
	});

	appcan.ready(function() {
		appcan.window.setBounce({
			bounceType: ['0'],
			downEndCall: function(type) {
				getData(type==0);
			}
		});
		getData(true) ;
		
	});
});